package patrol.mobile.com.mobilepatrol.activity.route_query;

import android.view.View;
import android.widget.ExpandableListView;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;

import java.util.List;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.widget.MyEL;

/**
 * Created by long on 2016/8/24.
 * 桥梁巡查列表
 */
public class SubOfficeAdapter extends BaseQuickAdapter<SubOffice> {
    private TotalRouteActivity context;
    public SubOfficeAdapter(TotalRouteActivity context, List<SubOffice> data) {
        super(context, data);
        this.context = (TotalRouteActivity) context;
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.item_sub_office;
    }

    @Override
    protected void convert(final BaseViewHolder holder, final SubOffice item) {
        holder.setText(R.id.tv, item.orgName);
        MyEL el = holder.getConvertView().findViewById(R.id.el);
        final List<RouteType> routeTypes = item.routeTypes;
        TypeAdapter routeListAdapter = new TypeAdapter(context,routeTypes);
        el.setAdapter(routeListAdapter);
        //遍历所有group,将所有项设置成默认展开
        for (int i=0; i<routeTypes.size(); i++)
        {
            el.expandGroup(i);
        }
        el.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                context.sendData(routeTypes.get(groupPosition).routeManages.get(childPosition));
                return false;
            }
        });

    }

}
